<?php

namespace App\Service;

use App\Models\MemberLevelConfigModel;
use App\Models\MemberModel;
use Carbon\Carbon;

class MemberService
{
    public static function checkVip($userId): ?array
    {
        $memberModel = MemberModel::getInfo($userId);
        $now         = Carbon::now();
        if ($memberModel) {
            if (!$now->between(Carbon::parse($memberModel->effective_time), Carbon::parse($memberModel->expire_time), false)) {
                $memberModel->vip_level = null;
            }
        }
        return $memberModel ? $memberModel->toArray() : null;
    }

    public function getVipRule($clientCode = 'ios'): ?array
    {
        return MemberLevelConfigModel::getConfigsByClientCode($clientCode);
    }
}
